From cc5d7244a8f3cee38323d61b837075b0b0f92b1a Mon Sep 17 00:00:00 2001 From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Tue, 4 Feb 2020 06:07:36 -0700 Subject: [PATCH] xcsv TIMET_TIME, TIMET_TIME_MS fix for the last fix. (#490) * xcsv TIMET_TIME, TIMET_TIME_MS fix for the last fix. e483407cf recently made a "fix" to TIMET_TIME_MS output. Unfortunately it used a non-standard strftime specifier. While this worked on linux systems it crashed with MSVC. This removes strftime processing from TIMET_TIME_MS output. This makes TIME_TIME, TIMET_TIME_MS analogous. Also input and output are invertbile. Note that the documentation for these fields never mentioned strptime or strftime, but says the are long intergers requiring long integer printf conversions. * Fix TIMET_TIME, TIMET_TIME_MS documentation. These have been converted to 64 bit values to prepare for 2038. * update style files for 64bit TIMET_TIME, TIMET_TIME_MS. --- internal_styles.cc | 8 ++++---- style/custom.style | 2 +- style/garmin301.style | 2 +- style/motoactv.style | 2 +- style/tabsep.style | 2 +- xcsv.cc | 30 ++++++++++++++---------------- xmldoc/chapters/styles.xml | 10 +++++----- 7 files changed, 27 insertions(+), 29 deletions(-) diff --git a/internal_styles.cc b/internal_styles.cc index 78f922928..d89785ffb 100644 --- a/internal_styles.cc +++ b/internal_styles.cc @@ -174,7 +174,7 @@ static char custom[] = "IFIELD LON_DIRDECIMAL, \"\", \"%c/%f\"\n" "IFIELD LAT_INT32DEG, \"\", \"%ld\"\n" "IFIELD LON_INT32DEG, \"\", \"%ld\"\n" - "IFIELD TIMET_TIME, \"\", \"%ld\"\n" + "IFIELD TIMET_TIME, \"\", \"%lld\"\n" "IFIELD EXCEL_TIME, \"\", \"%f\"\n" "# EPILOGUE:\n" @@ -309,7 +309,7 @@ static char garmin301[] = "#\n" "# INDIVIDUAL DATA FIELDS:\n" "#\n" - "IFIELD TIMET_TIME,\"\",\"%ld\"\n" + "IFIELD TIMET_TIME,\"\",\"%lld\"\n" "IFIELD LAT_DECIMAL, \"\", \"%f\"\n" "IFIELD LON_DECIMAL, \"\", \"%f\"\n" "IFIELD ALT_FEET, \"\", \"%fF\"\n" @@ -969,7 +969,7 @@ static char motoactv[] = "IFIELD IGNORE,\"\",\"%s\" # repetitions\n" "IFIELD TEMPERATURE,\"\",\"%.1f\"\n" "IFIELD IGNORE,\"\",\"%s\" # instant torque crank\n" - "IFIELD TIMET_TIME_MS,\"\",\"%ld\"\n" + "IFIELD TIMET_TIME_MS,\"\",\"%lld\"\n" "IFIELD ALT_METERS,\"\",\"%.1f\"\n" "IFIELD POWER,\"\",\"%.0f\"\n" "IFIELD IGNORE,\"\",\"%s\" # strides\n" @@ -1294,7 +1294,7 @@ static char tabsep[] = "IFIELD ALT_FEET, \"\", \"%fF\"\n" "IFIELD ALT_METERS, \"\", \"%fM\"\n" "IFIELD EXCEL_TIME, \"\", \"%f\"\n" - "IFIELD TIMET_TIME, \"\", \"%ld\"\n" + "IFIELD TIMET_TIME, \"\", \"%lld\"\n" "IFIELD GEOCACHE_DIFF,\"\",\"%3.1f\"\n" "IFIELD GEOCACHE_TERR,\"\",\"%3.1f\"\n" "IFIELD GEOCACHE_CONTAINER,\"\",\"%s\"\n" diff --git a/style/custom.style b/style/custom.style index 528ac85ed..b90556f7d 100644 --- a/style/custom.style +++ b/style/custom.style @@ -44,7 +44,7 @@ IFIELD LAT_DIRDECIMAL, "", "%c/%f" IFIELD LON_DIRDECIMAL, "", "%c/%f" IFIELD LAT_INT32DEG, "", "%ld" IFIELD LON_INT32DEG, "", "%ld" -IFIELD TIMET_TIME, "", "%ld" +IFIELD TIMET_TIME, "", "%lld" IFIELD EXCEL_TIME, "", "%f" # EPILOGUE: diff --git a/style/garmin301.style b/style/garmin301.style index 6c7a73956..2922986da 100644 --- a/style/garmin301.style +++ b/style/garmin301.style @@ -22,7 +22,7 @@ PROLOGUE Timestamp,Latitude, Longitude, Altitude(ft), heart rate # # INDIVIDUAL DATA FIELDS: # -IFIELD TIMET_TIME,"","%ld" +IFIELD TIMET_TIME,"","%lld" IFIELD LAT_DECIMAL, "", "%f" IFIELD LON_DECIMAL, "", "%f" IFIELD ALT_FEET, "", "%fF" diff --git a/style/motoactv.style b/style/motoactv.style index 8cbe2599c..9029f41cb 100644 --- a/style/motoactv.style +++ b/style/motoactv.style @@ -28,7 +28,7 @@ IFIELD LAT_DECIMAL,"","%.6f" IFIELD IGNORE,"","%s" # repetitions IFIELD TEMPERATURE,"","%.1f" IFIELD IGNORE,"","%s" # instant torque crank -IFIELD TIMET_TIME_MS,"","%ld" +IFIELD TIMET_TIME_MS,"","%lld" IFIELD ALT_METERS,"","%.1f" IFIELD POWER,"","%.0f" IFIELD IGNORE,"","%s" # strides diff --git a/style/tabsep.style b/style/tabsep.style index 1dd43bbdc..7857d8003 100644 --- a/style/tabsep.style +++ b/style/tabsep.style @@ -44,7 +44,7 @@ IFIELD LON_DIR, "", "%c" IFIELD ALT_FEET, "", "%fF" IFIELD ALT_METERS, "", "%fM" IFIELD EXCEL_TIME, "", "%f" -IFIELD TIMET_TIME, "", "%ld" +IFIELD TIMET_TIME, "", "%lld" IFIELD GEOCACHE_DIFF,"","%3.1f" IFIELD GEOCACHE_TERR,"","%3.1f" IFIELD GEOCACHE_CONTAINER,"","%s" diff --git a/xcsv.cc b/xcsv.cc index d61d9f73a..a9750bc4c 100644 --- a/xcsv.cc +++ b/xcsv.cc @@ -611,10 +611,15 @@ XcsvFormat::xcsv_parse_val(const QString& value, Waypoint* wpt, const XcsvStyle: /* Time as Excel Time */ wpt->SetCreationTime(excel_to_timet(atof(s))); break; - case XT_TIMET_TIME: + case XT_TIMET_TIME: { /* Time as time_t */ - wpt->SetCreationTime((time_t) atol(s)); - break; + bool ok; + wpt->SetCreationTime(value.toLongLong(&ok)); + if (!ok) { + warning("parse of string '%s' on line number %d as TIMET_TIME failed.\n", s, line_no); + } + } + break; case XT_TIMET_TIME_MS: { /* Time as time_t in milliseconds */ bool ok; @@ -1342,20 +1347,13 @@ XcsvFormat::xcsv_waypt_pr(const Waypoint* wpt) buff = QString::asprintf(fmp.printfc.constData(), timet_to_excel(wpt->GetCreationTime().toTime_t())); break; case XT_TIMET_TIME: - /* time as a time_t variable */ - { - time_t tt = wpt->GetCreationTime().toTime_t(); - buff = QString::asprintf(fmp.printfc.constData(), tt); - } - break; - - case XT_TIMET_TIME_MS: { + /* time as a time_t variable in seconds */ + buff = QString::asprintf(fmp.printfc.constData(), wpt->GetCreationTime().toSecsSinceEpoch()); + break; + case XT_TIMET_TIME_MS: /* time as a time_t variable in milliseconds */ - buff = writetime("%s", wpt->GetCreationTime().toTime_t(), false); - buff += QString::asprintf("%03d", wpt->GetCreationTime().time().msec()); - - } - break; + buff = QString::asprintf(fmp.printfc.constData(), wpt->GetCreationTime().toMSecsSinceEpoch()); + break; case XT_YYYYMMDD_TIME: buff = QString::asprintf(fmp.printfc.constData(), time_to_yyyymmdd(wpt->GetCreationTime())); break; diff --git a/xmldoc/chapters/styles.xml b/xmldoc/chapters/styles.xml index 1fd535470..1e89332ab 100644 --- a/xmldoc/chapters/styles.xml +++ b/xmldoc/chapters/styles.xml @@ -807,24 +807,24 @@ longitude)
TIMET_TIME TIMET_TIME is the waypoint's creation time, if any. This is actually - the integer seconds since 1/1/1970 (let's not start the holy war) and - is handled internally as a LONG INTEGER and requires a LONG INTEGER + the integer seconds since 1970-01-01T00:00:00 UTC. It + is handled internally as a 64 bit integer and requires a LONG LONG INTEGER printf conversion. example: - IFIELD TIMET_TIME,"","%ld" + IFIELD TIMET_TIME,"","%lld"
TIMET_TIME_MS TIMET_TIME_MS is the same as TIMET_TIME, but expressed in milliseconds. - It too is handled internally as a LONG INTEGER and requires a LONG INTEGER + It too is handled internally as a 64 bit integer and requires a LONG LONG INTEGER printf conversion. example: - IFIELD TIMET_TIME_MS,"","%ld" + IFIELD TIMET_TIME_MS,"","%lld"
-- 2.30.2